package tcc.wa.view.activity;

import java.util.List;

import tcc.wa.model.DailyWeatherForecast;
import tcc.wa.presenter.DailyWeatherForecastPresenter;
import tcc.wa.presenter.view.DailyWeatherForecastView;
import tcc.wa.view.activity.base.ListActivityBase;
import tcc.wa.view.adapter.DailyWeatherForecastAdapter;
import android.os.Bundle;
import android.view.View;

/**
 * Activity class to display DailyWeatherForecasts.
 */
public class DailyWeatherForecastActivity extends ListActivityBase implements DailyWeatherForecastView {

	private DailyWeatherForecastPresenter presenter;
	
	public DailyWeatherForecastActivity() {
		presenter = new DailyWeatherForecastPresenter(this);
	}
	
	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		presenter.onCreate();
	}
	
	/* (non-Javadoc)
	 * @see android.app.Activity#onResume()
	 */
	@Override
	public void onResume() {
		super.onResume();
		presenter.updateCachedForecast();
	}
	
	/* (non-Javadoc)
	 * @see tcc.wa.presenter.view.View#initView(int)
	 */
	public void initView(int layoutId) {
		setContentView(layoutId);
	}
	
	/* (non-Javadoc)
	 * @see tcc.wa.presenter.view.DailyWeatherForecastView#setDailyWeatherForecastList(java.util.List)
	 */
	public void setDailyWeatherForecastList(List<DailyWeatherForecast> forecasts) {
		DailyWeatherForecastAdapter adapter = new DailyWeatherForecastAdapter(this, forecasts);
		setListAdapter(adapter);
	}
	
	/**
	 * Updates DailyWeatherForecasts.
	 *
	 * @param view the view of origin
	 */
	public void updateForecast(View view) {
		presenter.updateForecast();
	}
}
